import cv2
import os

def get_boundary():
    path = "dataset/DUTS-TE-Mask"
    save_path = "src/DUTS-TE-Mask"
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    for i in os.listdir(path):
        mask = cv2.imread(os.path.join(path, i))
        ret, mask = cv2.threshold(mask, 128, 255, cv2.THRESH_BINARY)
        mean = cv2.blur(mask, (3, 3))
        sub = mask - mean
        ret, binary = cv2.threshold(sub, 128, 255, cv2.THRESH_BINARY)
        cv2.imwrite(os.path.join(save_path, i), binary)
        print(os.path.join(save_path, i))
        # cv2.imshow('mask', mask)
        # cv2.imshow('mean', mean)
        # cv2.imshow('sub', sub)
        # cv2.imshow('binary', binary)
        # cv2.waitKey()

if __name__ == '__main__':
    get_boundary()